import request from '@/utils/request'

// 获取代理列表
export function getAgentList(params) {
  console.log('调用getAgentList API，参数:', params)
  return request({
    url: '/admin/agents',
    method: 'get',
    params
  })
}

// 获取代理详情
export function getAgentDetail(agentId) {
  console.log('调用getAgentDetail API，代理ID:', agentId)
  return request({
    url: `/admin/agents/${agentId}`,
    method: 'get'
  })
}

// 添加代理
export function addAgent(data) {
  console.log('调用addAgent API，数据:', data)
  return request({
    url: '/admin/agents/add',
    method: 'post',
    data
  })
}

// 更新代理
export function updateAgent(agentId, data) {
  console.log('调用updateAgent API，代理ID:', agentId, '数据:', data)
  return request({
    url: `/admin/agents/edit/${agentId}`,
    method: 'post',
    data
  })
}

// 删除代理
export function deleteAgent(agentId) {
  console.log('调用deleteAgent API，代理ID:', agentId)
  return request({
    url: `/admin/agents/delete/${agentId}`,
    method: 'post'
  })
}

// 获取代理树形结构
export function getAgentTree() {
  console.log('调用getAgentTree API')
  return request({
    url: '/admin/agents/tree',
    method: 'get'
  })
}

// 获取佣金记录列表
export function getCommissionList(params) {
  console.log('调用getCommissionList API，参数:', params)
  return request({
    url: '/admin/agents/commissions',
    method: 'get',
    params
  })
}

// 结算佣金
export function settleCommission(commissionId) {
  console.log('调用settleCommission API，佣金ID:', commissionId)
  return request({
    url: `/admin/agents/settle/${commissionId}`,
    method: 'post'
  })
}

export function baseOpenCard(data) {
  return request({
    url: `/admin/card/record`,
    method: 'post',
    data
  })
}
